/**
 * Created by admin on 01-02-2015.
 */
var qs = require('querystring');
var express = require('express');
var models =require('../server/model/models');
var router = express.Router();


var mongoose = require('mongoose');
var MyModel = mongoose.model('MyModel');
//var AppModel = mongoose.model('AppModel');



/* GET users listing. */
/*
router.post('/putName', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");

    console.log(req.body);

    var message = new MyModel(req.body);
    message.date = new Date();
    message.save(function () {
       // res.send(req.body);
     res.send('Saved Successfully');
    });

});
*/

router.post('/putApp', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");

    console.log(req.body);

    var message = new MyModel(req.body);
    message.save(function () {
        // res.send(req.body);
        res.send('Saved Successfully');
    });

});

router.get('/getAllNames', function(req, res) {


    MyModel.find({}, function(err, users) {
        var userMap = [];

        users.forEach(function(user) {
            userMap.push(user);
        });
        console.log(userMap);
        res.send(userMap);
    });
});

router.get('/getAllApps', function(req, res) {


    MyModel.find({}, function(err, apps) {
        var appMap = [];

        users.forEach(function(appn) {
            appMap.push(appn);
        });
        console.log(appMap);
        res.send(appMap);
    });
});



/* GET users listing. */
router.get('/companyfn', function(req, res, next) {
    res.send('Companey :: Evolv');
});




module.exports = router;
